package com.common.project.table;
import lombok.Data;
import lombok.experimental.Accessors;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import javax.persistence.*;
import javax.validation.constraints.Pattern;
import java.util.Date;
import java.util.Set;

/**
 * <p>
 *
 * </p>
 *
 * @author jiangshicun
 * @since 2019-06-13
 */
@Entity
@Table(name = "user")
@org.hibernate.annotations.Table(appliesTo = "user",comment="用户表")
@Data
@Accessors(chain = true)
public class User extends Model<User> {
    @Id //这是一个主键
    @GeneratedValue(strategy = GenerationType.IDENTITY)//自增主键
    private Long id;
    @Column(name = "username",length = 50,columnDefinition = "varchar(50) COMMENT '用户姓名'") //这是和数据表对应的一个列
    private String username;
    @Column(name = "phone",length = 50,columnDefinition = "varchar(50) COMMENT '手机号'") //这是和数据表对应的一个列
    private String phone;
    @Column(name = "age",length = 4,columnDefinition = "int(11) COMMENT '年龄'") //这是和数据表对应的一个列
    private Integer age;
    @Column(name = "avatar",length = 50,columnDefinition = "varchar(50) COMMENT 'avatar'") //这是和数据表对应的一个列
    private String avatar;
    @Column(name = "email",length = 50,columnDefinition = "varchar(50) COMMENT '邮箱'")
    @Pattern(regexp = "([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}",message = "格式错误")
    private String email;
    @Column(name = "password",length = 50,columnDefinition = "varchar(50) COMMENT '密码'")
    private String password;

    @Column(nullable = false, columnDefinition = "TINYINT", length = 1)
    private Boolean enabled;

    @Column(name = "last_password_reset_time")
    private Date lastPasswordResetTime;

    @ManyToMany
    @JoinTable(name = "users_roles", joinColumns = {@JoinColumn(name = "user_id",referencedColumnName = "id")}, inverseJoinColumns = {@JoinColumn(name = "role_id",referencedColumnName = "id")})
    private Set<Role> roles;

    @OneToOne
    @JoinColumn(name = "job_id")
    private Job job;

    @OneToOne
    @JoinColumn(name = "dept_id")
    private Dept dept;

    @Column(name = "create_time",columnDefinition = "datetime DEFAULT NULL COMMENT '创建时间'")
    private Date createTime;

    public @interface Update {}

}

